
#include "../include/api.h"

char buf_sht_window[256*192] ;

void HariMain () { 
	int fh ;
	int i =0;
	char c ;
	char str[50] ;
	char strs[10][10] ;
	int cmd_win ;



	i = api_cmdline (str ,50);
	c = str_split (str,strs,' ');


	cmd_win = api_openwin(buf_sht_window,256,200, -1, "vi");
	if (c >=1){
		fh =  api_fopen (strs[1]);
		for (;;){ 
			if (api_fread(&c ,1,fh) ==0) { 
				break;
			}
		 //api_putchar(c);
		 api_putchar2win(cmd_win,c);
		}
		api_fclose (fh);
		api_end ();	
	}
		

	for (;;){ 

	}
}


//以sp为分割符 分割字符串, 返回切出的总字符串个数
int str_split (char source[] ,char dest[][10]  ,char sp) { 
	int length = strlen (source);
	int flag = 0  ; //匹配到字符串
	int i=0,j=0,k=0;
	if (length <=0) {return 0;}

	for (i =0 ;i<length;i++) {
		if (source[i] ==sp) { 
			if (flag ==0){ //表示是命令之前的空格
				continue ;
			}else {  //表示是第一个命令串之后的空格
				dest[j][k] ='\0' ;
				k = 0 ;
				j++ ;
				flag = 0 ;
			}
		}
		else {
			flag =1 ;
			dest[j][k] = source[i];
			k++ ;
		}
	}
	if (source[length-1] !=sp) { 
		dest[j][k] ='\0' ;
		j++ ;
	}
	return j ;
}
